Skip to content

Upgrade to Zustand 5.x#1405

Open
IDisposable wants to merge 2 commits into
jetkvm:devfrom
IDisposable:chore/zustand
Open

Upgrade to Zustand 5.x#1405
IDisposable wants to merge 2 commits into
jetkvm:devfrom
IDisposable:chore/zustand

Conversation

@IDisposable
Copy link
Copy Markdown
Contributor

@IDisposable IDisposable commented Apr 9, 2026

Summary

Upgrade to current version of Zustand.

  • Fixed the NetworkState store in stores.ts to be passing around the data, not the data+mutators.
  • Fixed state use in devices.$id.settings.network.tsx to use useShallow on each of the individual properties of the NetworkState instead of the entire block of state so we don't re-render on any change.
  • Use useShallow for version information in devices.$id.settings.general._index.tsx
  • Fix timer leaked in devices.$id.settings.network.tsx in LifeTimeLabel mount's useEffect
  • Removed resolveOnRtcReady in devices.$id.settings.network.tsx as it leaks a subscription when things were not ready. The code in jsonrpc.ts waitForRtcReady handles this much more robustly.
  • Removed excess toast (about DHCP) when saving network settings (we already toasted those) in devices.$id.settings.network.tsx
  • Added missing git config --global --add safe.directory in the build_cgo.sh for Docker native library builds

Checklist

  • Ran make test_e2e locally and passed
  • One problem per PR (no unrelated changes)
  • Lints pass; CI green

Note

Medium Risk
State management was upgraded and several components changed their store selectors/mutators, which can subtly affect re-render behavior and network settings UI state updates. Also adjusts Docker/native build scripting, which could impact CI/build environments.

Overview
Upgrades UI state management to zustand@5 (updates package.json/lockfile) and adjusts call sites to use the new zustand/shallow helper for stable, minimal subscriptions.

Refactors useNetworkStateStore typing and updates DHCP lease mutation to be immutable, and updates the network/general settings routes to select only needed store fields (reducing re-renders). Also fixes a LifeTimeLabel interval bug (no leaked interval / proper immediate update), removes a leaky RTC readiness helper in favor of the existing JSON-RPC readiness logic, and drops a redundant DHCP success toast.

Adds a git config --global --add safe.directory step in scripts/build_cgo.sh to avoid safe-directory errors when building the native library in Docker.

Reviewed by Cursor Bugbot for commit 2381c2c. Bugbot is set up for automated code reviews on this repo. Configure here.

@IDisposable IDisposable marked this pull request as ready for review April 9, 2026 18:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the UI state-management layer to Zustand 5.x and adapts store typing/selector usage in device settings routes to reduce unnecessary re-renders and prevent leaks, plus a small container build script adjustment.

Changes:

  • Bump zustand from ^4.5.2 to ^5.0.12 (and update lockfile).
  • Refactor NetworkState store typing and update network/general settings pages to use useShallow selectors and fix a setInterval leak pattern.
  • Add a Git safe.directory configuration in the CGO native build script for container builds.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ui/src/routes/devices.$id.settings.network.tsx Switch to useShallow selector for network state fields; remove RTC-ready helper; adjust LifeTimeLabel effect.
ui/src/routes/devices.$id.settings.general._index.tsx Use useShallow selector for version fields from the device store.
ui/src/hooks/stores.ts Split NetworkState data from store actions via NetworkStateStore; update DHCP lease expiry immutably.
ui/package.json Upgrade Zustand dependency to ^5.0.12.
ui/package-lock.json Lockfile updates for Zustand 5.x and its peer dependency metadata.
scripts/build_cgo.sh Add git config --global --add safe.directory ... before native build.
Files not reviewed (1)
  • ui/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/src/routes/devices.$id.settings.network.tsx Outdated
Comment thread scripts/build_cgo.sh Outdated
terryrankine added a commit to terryrankine/kvm that referenced this pull request May 7, 2026
- Bump zustand to ^5.0.12 in package.json and update lockfile
- Split NetworkState into pure data interface and NetworkStateStore
  (store interface extending it with action methods) — fixes type
  leakage of store actions into data-only consumers
- Replace mutable DHCP lease update with immutable spread to prevent
  stale-reference bugs in Zustand 5
- Add useShallow selectors to useNetworkStateStore and useDeviceStore
  callers that returned plain objects, preventing spurious re-renders
  in Zustand 5 where object identity is always checked

Fork-specific: VPN, audio, and IO stores are not in upstream and were
not touched. Only NetworkStateStore and DeviceStore call sites in
VersionContent and NetworkContent were updated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants